import Vue from 'vue'
import VueX from 'vuex'


Vue.use(VueX)

//封装数据项
const state = {
    startPoint:null,
    endPoint:null,
    guides: null,
    taskPoints: null,
    featurelinejson: null,
    featurepointjson: null
}

//计算属性
const getters = {
    getStartPoint(state){
        return state.startPoint;
    },
    getEndPoint(state){
        return state.endPoint;
    },
    getGuides(state) {
        return state.guides;
    },
    getPoints(state) {
        return state.points;
    },
    getLineFeature(state) {
        return state.featurelinejson;
    },
    getPointsFeature(state) {
        return state.featurepointjson;
    }
}

//封装对数据的直接操作
const mutations = {
    SETSTARTPOINT(state,point){
        state.startPoint = point;
    },
    SETENDPOINT(state,point){
        state.endPoint = point;
    },
    SETPOINTS(state, points) {
        state.points = points;
    },
    SETGUIDES(state,guides){
        state.guides = guides;
    },
    SETLINEFEATURE(state,linejson){
        state.featurelinejson = linejson;
    },
    SETPOINTFEATURE(state,pointjson){
        state.featurepointjson = pointjson;
    }

}

//封装前台对store数据的操作逻辑
const actions = {
    setPoints({commit}, points) {
        commit('SETPOINTS', points)
    },
    setGuides({commit}, points) {
        commit('SETGUIDES', points)
    },
    setLineGeoJson({commit}, linejson) {
        commit('SETLINEFEATURE', linejson)
    },
    setPointGeoJson({commit}, pointjson) {
        commit('SETPOINTFEATURE', pointjson)
    },
}

export default new VueX.Store({
    state,
    getters,
    mutations,
    actions
})